home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / models / ImageModel.as < prev    next >
Text File  |  2008-11-04  |  4KB  |  145 lines

  1. package com.jeroenwijering.models
  2. {
  3.    import com.jeroenwijering.events.ModelEvent;
  4.    import com.jeroenwijering.events.ModelStates;
  5.    import com.jeroenwijering.player.Model;
  6.    import flash.display.Bitmap;
  7.    import flash.display.Loader;
  8.    import flash.events.ErrorEvent;
  9.    import flash.events.Event;
  10.    import flash.events.IOErrorEvent;
  11.    import flash.events.ProgressEvent;
  12.    import flash.media.SoundMixer;
  13.    import flash.net.URLRequest;
  14.    import flash.utils.clearInterval;
  15.    import flash.utils.setInterval;
  16.    
  17.    public class ImageModel implements ModelInterface
  18.    {
  19.        
  20.       
  21.       private var interval:Number;
  22.       
  23.       private var loader:Loader;
  24.       
  25.       private var position:Number;
  26.       
  27.       private var model:Model;
  28.       
  29.       public function ImageModel(param1:Model)
  30.       {
  31.          super();
  32.          model = param1;
  33.          loader = new Loader();
  34.          loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
  35.          loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
  36.          loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
  37.       }
  38.       
  39.       public function stop() : void
  40.       {
  41.          SoundMixer.stopAll();
  42.          clearInterval(interval);
  43.          if(loader.contentLoaderInfo.bytesLoaded != loader.contentLoaderInfo.bytesTotal)
  44.          {
  45.             loader.close();
  46.          }
  47.          else
  48.          {
  49.             loader.unload();
  50.          }
  51.       }
  52.       
  53.       public function quality(param1:Boolean) : void
  54.       {
  55.          var stt:Boolean = param1;
  56.          try
  57.          {
  58.             Bitmap(loader.content).smoothing = stt;
  59.          }
  60.          catch(err:Error)
  61.          {
  62.          }
  63.       }
  64.       
  65.       public function seek(param1:Number) : void
  66.       {
  67.          clearInterval(interval);
  68.          position = param1;
  69.          play();
  70.       }
  71.       
  72.       public function volume(param1:Number) : void
  73.       {
  74.       }
  75.       
  76.       private function progressHandler(param1:ProgressEvent) : void
  77.       {
  78.          var _loc2_:* = undefined;
  79.          _loc2_ = Math.round(param1.bytesLoaded / param1.bytesTotal * 100);
  80.          model.sendEvent(ModelEvent.BUFFER,{"percentage":_loc2_});
  81.       }
  82.       
  83.       private function errorHandler(param1:ErrorEvent) : void
  84.       {
  85.          model.sendEvent(ModelEvent.ERROR,{"message":param1.text});
  86.       }
  87.       
  88.       public function load() : void
  89.       {
  90.          clearInterval(interval);
  91.          position = model.playlist[model.config["item"]]["start"];
  92.          loader.load(new URLRequest(model.playlist[model.config["item"]]["file"]));
  93.          model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.BUFFERING});
  94.          model.sendEvent(ModelEvent.BUFFER,{"percentage":0});
  95.       }
  96.       
  97.       private function timeInterval() : void
  98.       {
  99.          var _loc1_:* = undefined;
  100.          position = Math.round(position * 10 + 1) / 10;
  101.          _loc1_ = model.playlist[model.config["item"]]["duration"];
  102.          if(position >= _loc1_ && _loc1_ > 0)
  103.          {
  104.             clearInterval(interval);
  105.             SoundMixer.stopAll();
  106.             model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.COMPLETED});
  107.          }
  108.          else if(_loc1_ > 0)
  109.          {
  110.             model.sendEvent(ModelEvent.TIME,{
  111.                "position":position,
  112.                "duration":_loc1_
  113.             });
  114.          }
  115.       }
  116.       
  117.       public function play() : void
  118.       {
  119.          interval = setInterval(timeInterval,100);
  120.          model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.PLAYING});
  121.       }
  122.       
  123.       public function pause() : void
  124.       {
  125.          clearInterval(interval);
  126.          model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.PAUSED});
  127.       }
  128.       
  129.       private function loaderHandler(param1:Event) : void
  130.       {
  131.          model.mediaHandler(loader);
  132.          quality(model.config["quality"]);
  133.          play();
  134.          model.sendEvent(ModelEvent.META,{
  135.             "height":param1.target.height,
  136.             "width":param1.target.width
  137.          });
  138.          model.sendEvent(ModelEvent.LOADED,{
  139.             "loaded":param1.target.bytesLoaded,
  140.             "total":param1.target.bytesTotal
  141.          });
  142.       }
  143.    }
  144. }
  145.